java无法在eclipse控制台上打印结果
Hello, I'm trying to create a program to calculate the factorial of a number. The console doesn't show any errors but also doesn't show any results. What am I doing wrong? Thank you
public static void main(String[] args) {
}
public static int faculty(int n) {
n=5;
int x = 1;
if(n > 0){
for(int i = 1; i <= n; i++){
x = x*i;
}
}
System.out.println(x);
return x;
}
}
# 1 楼答案
你从来没有调用过教员(…)方法:
你还可以摆脱:
如果总是硬编码一个值,那么这就破坏了向方法传递参数的目的
还有,你为什么称这种方法为“能力”?可能是更具描述性的方法名称,比如
calculateFactorial
,因为这就是您试图计算的内容。让你的方法名具有描述性,这样我们就知道了这个方法的作用